package com.i.template.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.i.template.domain.PlayListDO;
import com.i.template.domain.vo.MusicVO;
import com.i.template.domain.vo.PlayListVO;
import com.i.template.mapper.PlayListMapper;
import com.i.template.service.IPlayListService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author lewis
 * @type class
 * @description
 * @since 2024/8/3
 */
@Service
@RequiredArgsConstructor
public class PlayListServiceImpl extends ServiceImpl<PlayListMapper, PlayListDO> implements IPlayListService {
    private final PlayListMapper mapper;
    @Override
    public PlayListVO queryPlayListById(Long id) {
        PlayListVO playListVO = new PlayListVO();
        Stream<PlayListDO> playListDO = mapper.listQueryPlayList(id).stream();
        playListDO.forEach(playDO -> {
            playListVO.setType(playDO.getType())
                    .setListId(playDO.getListId())
                    .setMusicVOS(BeanUtil.copyToList(playDO.getMusicDOS(),MusicVO.class));
        }
        );
        return playListVO;
    }

    @Override
    public List<PlayListVO> listQueryPlayList() {
        List<PlayListVO> playListVOS = new ArrayList<>();
        PlayListVO playListVO = new PlayListVO();
        Stream<PlayListDO> playListDO = mapper.listQueryPlayList().stream();
        playListDO.forEach(playDO -> {
            playListVO.setType(playDO.getType())
                    .setListId(playDO.getListId())
                    .setMusicVOS(BeanUtil.copyToList(playDO.getMusicDOS(),MusicVO.class));
            playListVOS.add(playListVO);
        }
        );
        return playListVOS;
    }
}
